//
//  CBJStatuesCell.swift
//  Weibo
//
//  Created by 崔健 on 16/5/24.
//  Copyright © 2016年 cbj. All rights reserved.
//

import UIKit
import SnapKit

class CBJStatuesCell: UITableViewCell {


    
    
    var statuesVM : CBJStatuesViewModel?{
    
        didSet{
        
            originalView.statuesVM = statuesVM
            
            self.toolBarTopCons?.uninstall()
            if statuesVM?.statues?.retweeted_status == nil {
                
                self.retweetedView.hidden = true
                toolBarView.snp_updateConstraints(closure: { (make) in
                    retweetedView.statuesVM = nil
                    self.toolBarTopCons = make.top.equalTo(originalView.snp_bottom).constraint
                })
            }else{
            
                self.retweetedView.hidden = false
                retweetedView.statuesVM = statuesVM
                toolBarView.snp_updateConstraints(closure: { (make) in
                self.toolBarTopCons = make.top.equalTo(retweetedView.snp_bottom).constraint
                })
            }
            
        }
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
    
        contentView.addSubview(originalView)
        contentView.addSubview(retweetedView)

        contentView.addSubview(toolBarView)
        
        originalView.snp_makeConstraints { (make) in
            
            make.left.top.right.equalTo(self.contentView)
        }
        
        retweetedView.snp_makeConstraints { (make) in
            
            make.top.equalTo(originalView.snp_bottom)
            make.left.right.equalTo(contentView)
        }
        
        toolBarView.snp_makeConstraints { (make) in
            
            self.toolBarTopCons = make.top.equalTo(retweetedView.snp_bottom).constraint
            make.left.right.equalTo(self.contentView)
            make.height.equalTo(36)
        }
        
        self.contentView.snp_makeConstraints { (make) in
            
            make.top.left.right.equalTo(self).constraint
            make.bottom.equalTo(toolBarView)
        }
        
    }
    
    private var toolBarTopCons : Constraint?
    
    lazy private var originalView : CBJStatuesOriginalView = CBJStatuesOriginalView()
    lazy private var retweetedView : CBJStatuesRewteetedView = CBJStatuesRewteetedView()
    
    lazy var pictureList : [CBJPicture] = [CBJPicture]()
    

    
    lazy private var toolBarView : CBJStatuesToolBarView = CBJStatuesToolBarView()
    
}
